package homework20.com.neuedu.Test;

import java.util.*;


class test1 {


    public static void main(String[] args) {
        List<String> list1 = new ArrayList<>();
        list1.add("黑神话悟空");
        list1.add("英雄联盟");
        list1.add("原神");

        // 使用增强的 for 循环遍历 List
        for (Object o : list1) {
            System.out.println(o);
        }

        // 使用迭代器遍历 List
        Iterator<String> iterator = list1.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }


        Map<Integer, String> map = new HashMap<>();
        map.put(1, "黑神话悟空");
        map.put(2, "王者荣耀");
        map.put(3, "原神");
        // 使用增强的 for 循环遍历 map
        for (Map.Entry<Integer, String> entry : map.entrySet()) {
            System.out.println(entry);
        }
        for (Object o : map.entrySet()) {
            System.out.println(o);
        }

        Iterator<Map.Entry<Integer, String>> iterator1 = map.entrySet().iterator();
        while (iterator1.hasNext()) {
            Map.Entry<Integer, String> entry = iterator1.next();
            System.out.println("Key  " + entry.getKey() + ", Value  " + entry.getValue());
        }
    }
}


